<?php

class Database {

  var $host;
  var $user;
  var $pass;
  var $dbname;

  var $dbh;

  function Database( $_host, $_user, $_pass, $_dbname ) {

    $this->host = $_host;
    $this->user = $_user;
    $this->pass = $_pass;
    $this->dbname = $_dbname;

    $this->dbh = mysql_connect( $this->host, $this->user, $this->pass );
    $error = mysql_errno( $this->dbh );

    if ( $error ) {
      error( E_ERROR, 'ERROR : Cannot Connect to Database \''. $this->dbname .'\'' );
      exit;
    }

    mysql_select_db( $this->dbname, $this->dbh );
    $error = mysql_errno( $this->dbh );     

    if ( $error ) {
      error( E_ERROR, 'ERROR : Cannot Select Database \''. $this->dbname .'\'' );
      exit;
    }

  }

  function _close() {
    mysql_close( $this );
  }

  function query( $_qry ) {

    $result = mysql_query( $_qry, $this->dbh );
    $error = mysql_errno( $this->dbh );

    if ( $error ) {
      error( E_ERROR, 'ERROR : Cannot Perform Query \''. $_qry .'\'' );
      exit;
    }

    return $result;

  }

}

?>
